<?
require 'global.php';
$cart=get_cart();

// 是否可以继续购买, 如果所有商品缺货, 则不可以购买 can buy
$can_buy=0;

// 购物车页面推荐产品 related items
$arr_hot=array();
/// 1. 获取购物车产品
$in_array=array();
foreach ($cart as $val){
	// pre($val);
	$in_array[]=$val['pid'];
}
// pre($in_array);
// pre($cart);
/// 2. 获取购物车产品的交叉产品
$where=array();
$where[]=array('name'=>'product_id','val'=>$in_array,'opn'=>'in');
$tem = $cross_sell->get_rows_advanced(32,$where);
$in_array=array();
foreach ($tem as $val){
	$in_array[]=$val['cross_product_id'];
}
/// 3. 获取交叉产品的资料
$where=array();
$where[]=array('name'=>'is_enabled','val'=>1,'opn'=>'=');
$where[]=array('name'=>'stock','val'=>0,'opn'=>'>');
$where[]=array('name'=>'id','val'=>$in_array,'opn'=>'in');
$tem = $product->get_rows_advanced(32,$where);
shuffle($tem);
$k=0;
foreach($tem as $row) { $arr_hot[]=$row; $k++; if($k==MAX_HOT_PRODUCT_SHOWN) break; }

if($k < MAX_HOT_PRODUCT_SHOWN){ // 数量不足
	$where=array();
	$where[]=array('name'=>'stock','val'=>0,'opn'=>'>');
	$where[]=array('name'=>'is_enabled','val'=>1);
	$tem = $product->get_rows_advanced(32,$where,'sold_quantity');
	shuffle($tem);
	foreach($tem as $row) { $arr_hot[]=$row; $k++; if($k==MAX_HOT_PRODUCT_SHOWN) break; }
}

// SEO 设置 seo tags
$title=WEB_CART.' - '.$config['SITE_COMPANY_'.LANG];
$kwd=$title;
$dpn=$kwd;

// view 加载视图
require VIEW.'cart.php';

// end of file